import 'dart:convert';
import 'package:ichinesereader/models/student/Assessment.dart';

List<TeacherAssessment> teacherAssessmentsFromJson(String str) =>
    List<TeacherAssessment>.from(
        json.decode(str).map((x) => TeacherAssessment.fromJson(x)));

String teacherAssessmentsToJson(List<TeacherAssessment> data) =>
    json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class TeacherAssessment {
  TeacherAssessment(
      {this.kind,
      this.audioType,
      this.students,
      this.textType,
      this.type,
      this.mode,
      this.commitTime,
      this.instruction,
      this.name,
      this.startTime,
      this.questionGroup,
      this.id,
      this.endTime,
      this.status,
      this.undone,
      this.submitted,
      this.waiting,
      this.waitingQuestionRecordId,
      this.undoneStudentList,
      this.waitingUserName});

  String? kind;
  String? audioType;
  List<StudentA>? students;
  String? textType;
  String? type;
  String? mode;
  int? commitTime;
  String? instruction;
  String? name;
  int? startTime;
  QuestionGroup? questionGroup;
  String? id;
  int? endTime;
  String? status;
  int? undone;
  int? submitted;
  int? waiting;
  String? waitingQuestionRecordId;
  List<StudentA>? undoneStudentList;
  String? waitingUserName;

  factory TeacherAssessment.fromJson(Map<String, dynamic> json) =>
      TeacherAssessment(
          kind: json["kind"] != null ? json["kind"] : null,
          audioType: json["audioType"] != null ? json["audioType"] : null,
          students: json["students"] != null && json["students"] != '[]'
              ? List<StudentA>.from(
                  json["students"].map((x) => StudentA.fromJson(x)))
              : null,
          textType: json["textType"] != null ? json["textType"] : null,
          type: json["type"] != null ? json["type"] : null,
          mode: json["mode"] != null ? json["mode"] : null,
          commitTime: json["commitTime"],
          instruction: json["instruction"] != null ? json["instruction"] : null,
          name: json["name"] != null ? json["name"] : 'No title',
          startTime: json["startTime"],
          questionGroup: json["questionGroup"] != null
              ? QuestionGroup.fromJson(json["questionGroup"])
              : null,
          id: json["id"],
          endTime: json["endTime"],
          status: json["status"] != null ? json["status"] : null,
          undone: json["undone"],
          waiting: json["waiting"],
          submitted: json["submitted"],
          waitingQuestionRecordId: json["waitingQuestionRecordId"],
          waitingUserName: json["waitingUserName"],
          undoneStudentList: json["undoneStudentList"] != null
              ? List<StudentA>.from(
                  json["undoneStudentList"].map((x) => StudentA.fromJson(x)))
              : null);

  Map<String, dynamic> toJson() => {
        "kind": kind,
        "audioType": audioType,
        "students": students != null
            ? List<dynamic>.from(students!.map((x) => x.toJson()))
            : null,
        "textType": textType,
        "type": type,
        "mode": mode,
        "commitTime": commitTime,
        "instruction": instruction,
        "name": name,
        "startTime": startTime,
        "questionGroup": questionGroup != null ? questionGroup?.toJson() : null,
        "id": id,
        "endTime": endTime,
        "status": status,
        "undone": undone,
        "waiting": waiting,
        "submitted": submitted,
        "waitingQuestionRecordId": waitingQuestionRecordId,
        "waitingUserName": waitingUserName,
        "undoneStudentList": undoneStudentList != null
            ? List<dynamic>.from(undoneStudentList!.map((x) => x.toJson()))
            : null
      };
}

class StudentA {
  StudentA({
    this.firstName,
    this.lastName,
    this.userName,
  });

  String? firstName;
  String? lastName;
  String? userName;

  factory StudentA.fromJson(Map<String, dynamic> json) => StudentA(
        firstName: json["firstName"] != null ? json["firstName"] : null,
        lastName: json["lastName"] != null ? json["lastName"] : null,
        userName: json["userName"],
      );

  Map<String, dynamic> toJson() => {
        "firstName": firstName,
        "lastName": lastName,
        "userName": userName,
      };
}

class QuestionGroupSimple {
  QuestionGroupSimple({
    this.imageLink,
    this.id,
    this.title,
    this.bookId,
  });

  String? imageLink;
  String? id;
  String? title;
  String? bookId;

  factory QuestionGroupSimple.fromJson(Map<String, dynamic> json) =>
      QuestionGroupSimple(
        imageLink: json["imageLink"],
        id: json["id"],
        title: json["title"],
        bookId: json["bookId"],
      );

  Map<String, dynamic> toJson() => {
        "imageLink": imageLink,
        "id": id,
        "title": title,
        "bookId": bookId,
      };
}
